{include file="public/header" /}
<body class="gray-bg">
<div class="wrapper wrapper-content animated fadeInRight">
    <div class="ibox float-e-margins">
        <div class="ibox-title">
            <h5>广告位列表</h5>
        </div>
        <div class="ibox-content">
            <div class="row">
                <div class="col-sm-12">
                    <div class="col-sm-2" style="width: 100px">
                        <div class="input-group">
                            <a href="{:url('add_position')}">
                                <button class="btn btn-outline btn-primary" type="button">添加广告位</button>
                            </a>
                        </div>
                    </div>
                </div>
            </div>
            <div class="example-wrap">
                <div class="example">
                    <table class="layui-table"
                           lay-data="{id:'position',height:'full-210',url:'index_position',method:'post',page:true}"
                           lay-filter="position">
                        <thead>
                        <tr>
                            <th lay-data="{title:'ID',field:'id',width:60,fixed:true,align:'center'}"></th>
                            <th lay-data="{title:'位置名称',field:'name',width:150}"></th>
                            <th lay-data="{title:'排序',field:'orderby',width:80,align:'center',sort:true}"></th>
                            <th lay-data="{title:'状态',field:'status',templet:'#status',width:120,align:'center'}"></th>
                            <th lay-data="{title:'添加时间',field:'create_time',width:180,align:'center',sort:true}"></th>
                            <th lay-data="{title:'更新时间',field:'update_time',width:180,align:'center',sort:true}"></th>
                            <th lay-data="{title:'操作',toolbar:'#toolbar',width:150,fixed:'right',align:'center'}"></th>
                        </tr>
                        </thead>
                    </table>
                    <script type="text/html" id="status">
                        <input type="checkbox" name="status" value="{{d.id}}"  lay-skin="switch" lay-text="开启|关闭" lay-filter="status"
                               {{d.status==1?'checked':''}}>
                    </script>
                    <script type="text/html" id="toolbar">
                        <a href="edit_position/id/{{d.id}}" class="btn btn-primary btn-xs btn-outline">
                            <i class="fa fa-paste"></i> 编辑</a>&nbsp;&nbsp;
                        <a href="javascript:;" onclick="del_position({{d.id}})"
                           class="btn btn-danger btn-xs btn-outline">
                            <i class="fa fa-trash-o"></i> 删除</a>
                    </script>
                </div>
            </div>
        </div>
    </div>
</div>
</div>
{include file="public/footer" /}


<script type="text/javascript">

var form = layui.form;
    /**
     * 删除广告位
     */
    function del_position(id) {
        layer.confirm('确认删除此广告位?', {icon: 3, title: '提示'}, function (index) {
            //do something
            $.getJSON('./del_position', {'id': id}, function (res) {
                if (res.code == 1) {
                    layer.msg(res.msg, {icon: 1, time: 1500, shade: 0.1}, function () {
                        window.location.href = "{:url('ad/index_position')}";
                    });
                } else {
                    layer.msg(res.msg, {icon: 0, time: 1500, shade: 0.1});
                }
            });
            layer.close(index);
        })

    }
    /**
     * 广告位状态
     */
    form.on('switch(status)', function (obj) {
        $.post("{:url('position_state')}", {id: this.value}, function (result) {
            //layer.tips(result.msg, obj.othis, {tips: 4});
        });
    });

</script>
</body>
</html>